<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class General_m extends MY_Model {

	public function __construct()
	{
		parent::__construct();
		$this->load->library('music');
		$this->load->library('country_city');
	}

	function index(){
		$data = $this->music->getListRecords();
	 	
		return $data;
	}
	
	function music_edit(){
		$id = $this->uri->segment(5,0);
		return $this->music->getMusicRecordBy_id($id);
	}
	
	function music_delete(){
		$id = $this->uri->segment(5,0);
		$this->music->deleteRecord_id($id);
		$this->session->set_flashdata('success', lang('dataman.success'));
		
		redirect(site_url('admin/dataman/general'));
	}
	
	function music_save(){
		$id = intval($_POST['id']);
		$name = $_POST['name'];
		 
		$rStt = $this->music->saveMusicName($id, $name);
		if($rStt){
			$this->session->set_flashdata('success', lang('dataman.success'));
			echo 'OK';
		}else{
			$this->session->set_flashdata('error', lang('dataman.error').". ".lang('dataman.error.duplicate'));
			echo 'noOK';
		}
		exit();
	}
	
	function country(){
		$data = $this->country_city->getListRecords_country(); 	
		return $data;
	}
	
	function country_edit(){
		$id = $this->uri->segment(5,0);
		return $this->country_city->getCountryRecordBy_id($id);
	}
	
	function country_delete(){
		$id = $this->uri->segment(5,0);
		$this->country_city->deleteCountryRecord_id($id);
		$this->session->set_flashdata('success', lang('dataman.success'));
		
		redirect(site_url('admin/dataman/general/country'));
	}
	
	function country_save(){
		$id = intval($_POST['id']);
		$name = $_POST['name'];
		$code = $_POST['code'];
		$country_origin_code = $_POST['country_origin_code'];
		
		$rStt = $this->country_city->saveCountry($id, $name, $code, $country_origin_code);
		if($rStt){
			$this->session->set_flashdata('success', lang('dataman.success'));
			echo 'OK';
		}else{
			$this->session->set_flashdata('error', lang('dataman.error').". ".lang('dataman.error.duplicate'));
			echo 'noOK';
		}
		exit();
	}
	
	function city(){
		$data = $this->country_city->getListRecords_city(); 	
		return $data;
	}
	
	function city_add(){
		return array('city'=>'', 'country'=>$this->country_city->getListRecords_country());
	}
	
	function city_edit(){
		$id = $this->uri->segment(5,0);
		return array('city'=>$this->country_city->getCityRecordBy_id($id), 'country'=>$this->country_city->getListRecords_country() );
	}
	
	function city_delete(){
		$id = $this->uri->segment(5,0);
		$this->country_city->deleteCityRecord_id($id);
		$this->session->set_flashdata('success', lang('dataman.success'));
		
		redirect(site_url('admin/dataman/general/city'));
	}
	
	function city_save(){
		$id = intval($_POST['id']);
		$name = $_POST['name'];
		$code = $_POST['code'];
		$country_id = $_POST['country_id'];
		
		$rStt = $this->country_city->saveCity($id, $name, $code, $country_id);
		if($rStt){
			$this->session->set_flashdata('success', lang('dataman.success'));
			echo 'OK';
		}else{
			$this->session->set_flashdata('error', lang('dataman.error').". ".lang('dataman.error.duplicate'));
			echo 'noOK';
		}
		exit();
	}
}
